package com.movie.demo.controller;
import com.movie.demo.pojo.Order;
import com.movie.demo.pojo.User;
import com.movie.demo.pojo.vo.OrderInfo;
import com.movie.demo.Utlis.result.CommonResult;
import com.movie.demo.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Queue;

@RestController
@CrossOrigin
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/Order")
    public CommonResult<List> OrderSelect(){
        List<OrderInfo> orderInfos= orderService.Selectorder();
        if(orderInfos!=null){
            return CommonResult.success(orderInfos);
        }
        return CommonResult.failed();
    }
    @PostMapping("/DeleteOrder")
    public CommonResult Delete(@RequestBody Order order){
        boolean result=orderService.deleteOrder(order.getOid());
        if (result) {
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }
    @PostMapping("/addOrder")
    public CommonResult addOrder(@RequestBody Order order){
        boolean result=orderService.addOrder(order);
        if (result){
          return CommonResult.success(result);
        }
        return CommonResult.failed();
    }
    @RequestMapping("/SearchOrder")
    public CommonResult<List> searchOrder(@RequestBody User user){
        List<OrderInfo> orderInfos= orderService.searchOrder(user.getUid());
            return CommonResult.success(orderInfos);
    }
    @PostMapping("/UpdateOrder")
    public CommonResult updateOrder(@RequestBody OrderInfo orderInfo){
        boolean result= orderService.updateOrder(orderInfo);
        if (result){
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }
    @PostMapping("/UpdateOrderState")
    public CommonResult updateOrderState(@RequestBody Order order){
        boolean result=orderService.UpdateOrderState(order.getOid(),order.getState());
        return CommonResult.success(result);
    }
}
